﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Message;

public partial class admin_Message_Message : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    ///**************************************************
    /// <summary>
    /// depiction：实现对的留言的绑定
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Writer：作者中文名
    ///Create Date：<方法创建日期，格式：YYYY-MM-DD>
    ///**************************************************

    private void Bind()
    {
        btnDelete.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
        //IMessage RM = new RMessage();
        //返回全部留言
        //DataTable da = RM.GetDataTable();
        //DataView dv = da.DefaultView;
        //this.grdMessage.DataSource = dv;
        //this.grdMessage.DataBind();
        string Info = this.txtMessage.Text;
        string State = dropMessageState.SelectedValue;
        string Date = dropMessageDate.SelectedValue;


        string[] str = new string[4];
        str[0] = "SendUserID";
        str[1] = Info;
        str[2] = State;
        str[3] = Date;

        //定义IMessage接口
        IMessage RM = new RMessage();
        DataTable dt = RM.GetDataTable(str);
        DataView dv = dt.DefaultView;
        this.grdMessage.DataSource = dv;
        this.grdMessage.DataBind();
    }
    public string GetShortDate(string dateStr)
    {
        if (dateStr != string.Empty)
            return Convert.ToDateTime(dateStr).ToShortDateString();
        else
            return string.Empty;
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= grdMessage.Rows.Count - 1; i++)
        {

            CheckBox cbox = (CheckBox)grdMessage.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {

                int UserID = Convert.ToInt32(grdMessage.DataKeys[i].Value);
                IMessage RM = new RMessage();
                int m = RM.Delete(UserID);
            }
        }
        Bind();
    }

    protected void btnSelect_Click(object sender, EventArgs e)
    {
        string Info = this.txtMessage.Text;
        string State =dropMessageState.SelectedValue;
        string Date = dropMessageDate.SelectedValue;
        

        string[] str = new string[4] ;
        str[0] = "SendUserID";
        str[1] = Info;
        str[2] = State;
        str[3] = Date;
    
        //定义IMessage接口
        IMessage RM = new RMessage();
        DataTable dt = RM.GetDataTable(str);
        DataView dv = dt.DefaultView;
        this.grdMessage.DataSource = dv;
        this.grdMessage.DataBind();
    }
    protected void grdMessage_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdMessage.PageIndex = e.NewPageIndex;
        Bind();
    }
    public string GetCharacter(string str_Value)
    {
        if (str_Value== "1")
        {
            return "已读";
        }
        else if (str_Value == "0")
        {
            return "未读";
        }
        else if (str_Value == null && str_Value =="")
        {
            return "系统留言";
        }
        else
        {
            return "已回复";
        }
    }
    public string GetMessagePeople(string str_Value)
    {

        if (str_Value == null || str_Value == "")
        {
            return "系统留言";
        }
        else
        {
            return str_Value;
        }
    }
    
    protected void grdMessage_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
            e.Row.Attributes.Add("onMouseOut", "SetOldColor(this)");
        }
    }
  

}
